import request from './request'

// 岗位数据类型
export interface PositionData {
  id: number
  name: string
  code: string
  department: string
  departmentId: number
  level: string
  status: 'active' | 'inactive'
  description: string
  createTime: string
}

// 获取岗位列表
export const getPositionList = () => {
  return request({
    url: '/positions/list',
    method: 'post',
    data: {}
  })
}

// 获取岗位分页列表
export const getPositionPage = (params: {
  current: number
  size: number
  name?: string
  departmentId?: number
}) => {
  return request({
    url: '/positions/page',
    method: 'post',
    data: params
  })
}

// 新增岗位
export const addPosition = (position: Omit<PositionData, 'id' | 'createTime'> & { departmentId?: number | null }) => {
  return request({
    url: '/positions/add',
    method: 'post',
    data: position
  })
}

// 编辑岗位
export const updatePosition = (position: PositionData & { departmentId?: number | null }) => {
  return request({
    url: '/positions/update',
    method: 'post',
    data: position
  })
}

// 删除岗位
export const deletePosition = (id: number) => {
  return request({
    url: '/positions/delete',
    method: 'post',
    data: { id }
  })
}

// 切换岗位状态
export const togglePositionStatus = (id: number) => {
  return request({
    url: '/positions/toggle-status',
    method: 'post',
    data: { id }
  })
}